#!/bin/bash

if [ -z '{{userName}}' ]; then
    echo 'userName is empty'
    exit 1
fi

if [ -z '{{newPassword}}' ]; then
    echo 'newPassword is empty'
    exit 2
fi

if passwd --help | grep "stdin" > /dev/null 2>&1; then
    echo '{{newPassword}}' | passwd '{{userName}}' --stdin
else
    echo '{{userName}}:{{newPassword}}' | chpasswd
fi
